package lesson2;

//静态代理模式总结
//真实对象和代理对象都要实现同一接口
//代理对象要代理真实角色
//好处：
    //代理对象可以做很多真实对象做不了的事情
    //真实对象专注做自己的事情
public class StaticProxy {
    public static void main(String[] args) {
//        WeddingCompany weddingCompany = new WeddingCompany(new You());
//        weddingCompany.HappyMarry();
        You you = new You();
        new Thread(()->System.out.println("我爱你")).start();
        new WeddingCompany(new You1()).HappyMarry();
    }
}

interface Marry{
    void HappyMarry();
}

//真实角色，你去结婚
class You1 implements Marry{
    @Override
    public void HappyMarry() {
        System.out.println("小王要结婚了，超开心");
    }
}

//代理角色，帮助你结婚
class WeddingCompany implements Marry{
    private Marry target;

    public WeddingCompany(Marry target) {
        this.target = target;
    }

    @Override
    public void HappyMarry() {
        before();
        this.target.HappyMarry();
        after();
    }

    private void after() {
        System.out.println("结婚后，收尾款");
    }

    private void before() {
        System.out.println("结婚前，布置现场");
    }
}